from django.http import HttpResponse
from GZBlogSite.models import *
from django.template import RequestContext,loader
from django.shortcuts import render_to_response
# Create your views here.

def index(request):
    return HttpResponse("Hello World!")

def personIndex(request):
    person_list = Person.objects.all()
    template = loader.get_template('PersonIndex.html')
    context = RequestContext(request,{'person_list':person_list},
                             processors = [customs_proc])
    return HttpResponse(template.render(context));

def search(request):
    if 'q' in request.GET and request.GET['q']:
        q = request.GET['q']
        person_list = Person.objects.filter(username=q)

        return render_to_response('PersonIndex.html',
                                 {'person_list':person_list})
    else:
        raise Http404

def customs_proc(request):
    return {"address":request.META['REMOTE_ADDR']}
